package lg.minecraft.plugin.pokemonmenu.util;

import lombok.Getter;

import java.util.Objects;

/**
 * @author langle__
 * @version 1.0
 */
@Getter
public class Position {

    private final int box;
    private final int slot;

    public Position(int slot) {
        if (slot < 6) {
            this.box = -1;
            this.slot = slot;
        } else {
            int temp = slot - 6;
            this.box = temp != 0 ? 30 / temp : 0; // 防止除以0
            this.slot = temp != 0 ? 30 % temp : 0; // 防止取模0
        }
    }

    public Position(int box, int slot) {
        this.box = box;
        this.slot = slot;
    }

    /**
     * 判断该位置是否为队伍。
     *
     * @return 如果是队伍则返回 true
     */
    public boolean isParty() {
        return this.box <= -1;
    }

    /**
     * 判断该位置是否为 PC。
     *
     * @return 如果是 PC 则返回 true
     */
    public boolean isPC() {
        return this.box >= 0;
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) return true;
        if (object == null || getClass() != object.getClass()) return false;
        Position position = (Position) object;
        return getBox() == position.getBox() && getSlot() == position.getSlot();
    }

    @Override
    public int hashCode() {
        return Objects.hash(getBox(), getSlot());
    }
}
